﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ThoiTrang.Entities;
using System.Collections.Generic;
using ThoiTrang.Business;

public partial class UserControls_Vote : System.Web.UI.UserControl
{
    protected int qid = 0;
    protected string question = string.Empty;
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        this.btnVote.Click += new EventHandler(btnVote_Click);
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {       
        this.LoadData();        
    }

    protected void btnVote_Click(object sender, EventArgs e)
    {
        try
        {
            if (String.IsNullOrEmpty(Request["VoteFor"])) return;
            int optId = int.Parse(Request["VoteFor"]);
            if (a_Surveys_OptionService.Geta_Surveys_Option(optId).IsOtherOption)
            {
                Response.Redirect(String.Format("surveycomment.aspx?ckid={0}&qid={1}&title={2}&rqsurvey={3}_1", SessionManager.GetCookie(), qid, Server.UrlEncode(question), optId.ToString()));                
                
            }
            else
            {
                a_Surveys_OptionService.a_Surveys_Option_IncreaseOption(optId);
                Response.Redirect(String.Format("reportsurvey.aspx?sid={0}&ckid={1}", qid, SessionManager.GetCookie()));
            }            
        }
        catch (Exception ex)
        {
        }
    }

    protected void LoadData()
    {
        try
        {
            List<a_Surveys_Option> opts = a_Surveys_OptionService.Geta_Surveys_OptionList(out question, out qid);
            if (!Page.IsPostBack)
            {
                lbQuestion.InnerHtml = question;
                rptPoll.DataSource = opts;
                rptPoll.DataBind();
            }
        }
        catch (Exception ex)
        {
        }
    }
}
